package com.huiquan.management.dao;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.management.domain.UserAbility;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class UserAbilityDao extends EnhancedBaseDao<UserAbility> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "USER_ABILITY.";

	public UserAbilityDao() {
		super(space);
	}

	public UserAbility retrieveObjectByUserIdAndRuleId(long userId, int roleId) {

		Map<String, Object> param = new HashMap<>();
		param.put("userId", userId);
		param.put("roleId", roleId);

		return (UserAbility) this.retrieveObjectByMap(param);
	}

	public void initByUserIdAndRoleId(long userId, int roleId, int examPass) {

		UserAbility userAbility = new UserAbility();
		userAbility.setUserId(userId);
		userAbility.setExamType(roleId);
		userAbility.setExamPass(examPass);

		this.insert(userAbility);
	}

	public void updatePassFlagByUidAndRole(Integer passFlag, Long uid, Integer role) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("pass", passFlag);
		param.put("uid", uid);
		param.put("roleId", role);

		this.update(space + "UPDATE_PASS_FLAG", param, sqlMapClient);
	}
}
